package com.xiaodu.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: dutianjie
 * @date: 2021/4/15
 * @version: v1.0.0
 * @description: 测试 mvc 拦截器； 测试发现只拦截controller url； 不拦截自定义的servlet url
 **/
@Component
public class MyInterceptor1 implements HandlerInterceptor {

    // 方法执行前拦截
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("interceptor preHandle");
        return true;
    }

    // 方法处理后拦截
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("interceptor postHandle");

    }

    // 处理完成后，报错不报错都走
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("interceptor afterCompletion");
    }
}
